# code/stage4_merge.py

import pandas as pd
from paths import PROCESSED_DATA_DIR

issp = pd.read_parquet(PROCESSED_DATA_DIR / 'issp_final_combined_harmonized.parquet')
macro = pd.read_parquet(PROCESSED_DATA_DIR / 'final_macro_combined_all.parquet')

issp['C_ALPHAN'] = issp['C_ALPHAN'].astype(str)
issp['YEAR'] = issp['YEAR'].astype(int)
macro['C_ALPHAN'] = macro['C_ALPHAN'].astype(str)
macro['YEAR'] = macro['YEAR'].astype(int)

final_analysis = pd.merge(
    issp,
    macro,
    on=['C_ALPHAN', 'YEAR'],
    how='left'
)

final_analysis.to_parquet(
    PROCESSED_DATA_DIR / 'final_analysis_dataset.parquet',
    index=False
)
